﻿using System;
using System.Xml;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;

namespace Scan
{
    /// <summary>
    /// 设备API类
    /// Company:lenx
    /// Author:xiajp
    /// Creating Time:2010.11.19
    /// </summary>
    public class PDAInfoClass
    {

        //声明类、变量


        //实现自定义窗口及隐藏输入法
        #region
        [Flags()]
        public enum SWP : int
        {
            SWP_ASYNCWINDOWPOS = 0x4000,
            SWP_DEFERERASE = 0x2000,
            SWP_DRAWFRAME = 0x0020,
            SWP_FRAMECHANGED = 0x0020,
            SWP_HIDEWINDOW = 0x0080,
            SWP_NOACTIVATE = 0x0010,
            SWP_NOCOPYBITS = 0x0100,
            SWP_NOMOVE = 0x0002,
            SWP_NOOWNERZORDER = 0x0200,
            SWP_NOREDRAW = 0x0008,
            SWP_NOREPOSITION = 0x0200,
            SWP_NOSENDCHANGING = 0x0400,
            SWP_NOSIZE = 0x0001,
            SWP_NOZORDER = 0x0004,
            SWP_SHOWWINDOW = 0x0040
        }
        [DllImport("CoreDll.dll", SetLastError = true)]
        public static extern IntPtr FindWindow(string className, string WindowsName);

        [DllImport("aygshell.dll", SetLastError = true)]
        public static extern bool SHFullScreen(IntPtr hwndRequester, SHFS dwState);

        [DllImport("coredll.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetWindowPos(IntPtr hwnd, int hwnd2, int x, int y, int cx, int cy, SWP uFlags);

        [DllImport("coredll.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx, int cy, bool repaint);

        [DllImport("coredll.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("coredll.dll", SetLastError = true)]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("coredll.dll", EntryPoint = "EnableWindow")]
        public static extern bool EnableWindow(IntPtr hwnd, bool bEnable);

        [Flags()]
        public enum SHFS : int
        {
            SHOWTASKBAR = 0x0001,
            HIDETASKBAR = 0x0002,
            SHOWSIPBUTTON = 0x0004,
            HIDESIPBUTTON = 0x0008,
            SHOWSTARTICON = 0x0010,
            HIDESTARTICON = 0x0020,
        }
        public static int TaskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;

        public static void HideTaskbar()
        {
            IntPtr handle;
            try
            {
                // Find the handle to the Start Bar
                handle = FindWindow("HHTaskBar", null);

                // If the handle is found then hide the start bar
                if (handle != IntPtr.Zero)
                {
                    // Hide the start bar
                    SetWindowPos(handle, 0, 0, 0, 0, 0, SWP.SWP_HIDEWINDOW);
                }
            }
            catch
            {
                MessageBox.Show("Could not hide Start Bar.");
            }
        }

        public static void UnhideTaskbar()
        {
            IntPtr handle;
            try
            {
                // Find the handle to the Start Bar
                handle = FindWindow("HHTaskBar", null);

                // If the handle is found then show the start bar
                if (handle != IntPtr.Zero)
                {
                    // Show the start bar
                    SetWindowPos(handle, 0, 0, 0, Screen.PrimaryScreen.Bounds.Width, TaskbarHeight, SWP.SWP_SHOWWINDOW);
                }
            }
            catch
            {
                MessageBox.Show("Could not show Start Bar.");
            }
        }

        #endregion

        /// <summary>
        /// 播放声音
        /// </summary>
        /// <param name="szSound"></param>
        /// <param name="hModule"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        [DllImport("coredll.dll")]
        public static extern int PlaySound(
            string szSound,
            IntPtr hModule,
            int flags);
        [Flags]
        public enum Flags : int
        {
            SND_SYNC = 0x0000,

            SND_ASYNC = 0x0001,

            SND_NODEFAULT = 0x0002,

            SND_MEMORY = 0x0004,

            SND_LOOP = 0x0008,

            SND_NOSTOP = 0x0010,

            SND_NOWAIT = 0x00002000,

            SND_ALIAS = 0x00010000,

            SND_ALIAS_ID = 0x00110000,

            SND_FILENAME = 0x00020000,

            SND_RESOURCE = 0x00040004
        }



    }
}

